<template>
    <div classs="login-container">
        <div class="header">个人中心</div>
        <van-cell-group>
  <van-field
    v-model="username"
    required
    clearable
    label="用户名"
    right-icon="question-o"
    placeholder="请输入用户名"
    @click-right-icon="$toast('question')"
  />

  <van-field
    v-model="password"
    type="password"
    label="密码"
    placeholder="请输入密码"
    required
  />
</van-cell-group>
        <van-button size="large" type="danger" @click="loginIn">登录</van-button>
        <p class="reg">
            未登录？
            <a href="javascript:;" @click="register">去注册</a>
        </p>
   
    </div>
</template>
<script>
export default {
    data(){
        return{
            username:"",
            password:""
        }
    },
    
    methods: {
        register(){
            this.$router.push("register")
        },
        loginIn(){
            var userInfo={
                  username :this.username,
                  password :this.password
            }
           this.$http.post("v1/users/login",userInfo).then(result=>{
               console.dir(result)
               if(result.status===200){
                   this.$toast.success("登录成功")
                 localStorage.setItem('token',result.data.data.token)
               }else{
                  this.$toast.fail("登录失败")
               }
           })
        }
    },
}
</script>
<style lang="less">
    .reg{
        float:right;
    }
</style>
